package string;

public class Test {
    public static void main(String[] args) {
        String url = "http://www.baidu.com";
        String url1 = "www.4399.com";
        String url2 = "http://www.tedu.com";
        System.out.println(getHostName(url));
        System.out.println(getHostName(url1));
        System.out.println(getHostName(url2));
    }

    public static String getHostName(String url) {
//        int index1 = url.indexOf(".");
//        int index2 = url.indexOf(".", index1 + 1);
//        String sub = url.substring(index1 + 1, index2);
//        return sub;
        int index1 = url.indexOf(".") + 1;
        int index2 = url.indexOf(".", index1);
        String sub = url.substring(index1, index2);
        return sub;

    }
}


